package com.crazy.crazyproductservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.crazy.crazymodel.model.entity.NetWorth;
import com.crazy.crazymodel.model.entity.Product;
import com.crazy.crazymodel.model.vo.NetWorthVO;
import com.crazy.crazymodel.model.vo.ProductNetWorthVO;
import com.crazy.crazyproductservice.mapper.NetWorthMapper;
import com.crazy.crazyproductservice.service.NetWorthService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
 * NetWorthServiceImpl 净值
 *
 * @author 13259
 * @version 2024/05/08 03:26
 **/
@Service
@Slf4j
public class NetWorthServiceImpl extends ServiceImpl<NetWorthMapper, NetWorth> implements NetWorthService {
    @Override
    public ProductNetWorthVO productGetValue(int productId, HttpServletRequest request){
        // 创建一个 QueryWrapper 对象，设置查询条件
        QueryWrapper<NetWorth> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("productID", productId);
        List<NetWorth> netWorthList=this.getBaseMapper().selectList(queryWrapper);
        if(netWorthList.isEmpty()) {
            log.info("未找到符合的数据！");
        }

        ProductNetWorthVO productNetWorthVO = new ProductNetWorthVO();
        ProductNetWorthVO.NetWorthData netWorthData = new ProductNetWorthVO.NetWorthData();
        List<NetWorthVO> netWorthVOList = new ArrayList<>();

        for (NetWorth netWorth : netWorthList) {
            NetWorthVO netWorthVO = new NetWorthVO();
            netWorthVO.setDate(netWorth.getUpdateDate());
            netWorthVO.setValue(netWorth.getNetValue());
            netWorthVOList.add(netWorthVO);
        }

        // 设置产品列表
        netWorthData.setValues(netWorthVOList);
        // 设置响应代码
        productNetWorthVO.setMsg(200);
        // 设置数据
        productNetWorthVO.setData(netWorthData);

        return productNetWorthVO;
    }
}
